package com.sunsys.QuestionAnswer;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.naming.spi.DirStateFactory.Result;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class QuestionsDisplay
 */
//@WebServlet("/QuestionsDisplay")
public class QuestionsDisplay extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		String linkName = request.getParameter("name");
		String name1 = "answered";
		
		if(linkName.equals(name1)){
			QuestionsDAO dao = new QuestionsDAOImpl();
			QuestionDetails question = new QuestionDetails();
			
			List<QuestionDetails> details =dao.getAnsweredQuestions();
			Iterator<QuestionDetails> itr = details.iterator();
			while(itr.hasNext()) {
				question = itr.next();
				String qname = question.getQName();
				int qid = question.getQId();
				out.println("<a href=QuestionAndAnswerRetrieve?id="+qid+">"+qname+"</a><br>");
			}
		}
		String name2 = "unanswered";
		if(linkName.equals(name2)){
			QuestionsDAO dao = new QuestionsDAOImpl();
			QuestionDetails question = new QuestionDetails();
			List<QuestionDetails> details =dao.getUnAnsweredQuestions();
			Iterator<QuestionDetails> itr = details.iterator();
			while(itr.hasNext()) {
				question = itr.next();
				String qname = question.getQName();
				int qid = question.getQId();
				out.println("<a href=QuestionAndAnswerRetrive?id="+qid+">"+qname+"</a><br>");
			}
		}
		
	}

}
